package com.ys.context;

import com.ys.bean.factory.AbstractBeanFactory;
import com.ys.bean.factory.AutowireCapableBeanFactory;
import com.ys.bean.support.BeanDefinitionRegistry;
import com.ys.exception.BeanDefinitionStoreException;
import com.ys.xml.XmlBeanDefinitionReader;

/**
 * <p>@description:</p>
 *
 * @projectName: Spring-Mini
 * @packageName: com.com.ys.context
 * @className:
 * @author: shuangyang
 * @date: 1/15/17 6:02 PM
 */
public class ClassPathXmlApplicationContext extends AbstractApplicationContext {
    /*  the location of configuration*/
    private String configLocation;

    public ClassPathXmlApplicationContext(String configLocation) {
        this(new AutowireCapableBeanFactory(), configLocation);
    }


    public ClassPathXmlApplicationContext(AbstractBeanFactory beanFactory, String configLocation) {
        super(beanFactory);
        this.configLocation = configLocation;
        refresh();
    }

    @Override
    protected void loadBeanDefinitions(BeanDefinitionRegistry registry) throws BeanDefinitionStoreException {
        XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(registry);//将beanFactory的registry传递
        xmlBeanDefinitionReader.loadBeanDefinitions(configLocation);
    }
}


